﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Demo</title>
    @*     <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
    <title>Layui 导入按钮示例</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/css/layui.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/layui/2.6.8/layui.js"></script>
    <link href="//unpkg.com/layui@2.9.20/dist/css/layui.css" rel="stylesheet">  *@
    @* <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui@2.9.20/dist/css/layui.min.css"> *@
</head>

<script src="//unpkg.com/layui@2.9.21-rc/dist/layui.js"></script>
<body class="layui-padding-3">
    <h3>主生产计划</h3>
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix"></div>
                <label class="layui-form-label">生产计划编码：</label> 
                <input type="text"
                       name="A"
                       id="produceplanNumber"
                       placeholder="" lk
                       class="layui-input"
                       lay-affix="clear"
                       style="width: 200px" />
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <label class="layui-form-label">生产计划名称：</label>
                <input type="text"
                       name="B"
                       placeholder=""
                       lay-affix="clear"
                       id="produceplanName"
                       class="layui-input"
                       style="width: 200px" />
            </div>
        </div>
        <div class="layui-col-md4">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix"></div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block" style="width: 200px">
                        <select name="interest" lay-filter="aihao" id="produceplanStatus">
                            <option value=-1>选择状态</option>
                            <option value=1>新增</option>
                            <option value=2>变更</option>
                            <option value=3>确定</option>
                            <option value=4>取消</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-col-md4">
            <a class="layui-btn" lay-submit onclick="location.href='/produceplan/produceplanAdd'">
                添加
            </a>
            <button type="reset" class="layui-btn layui-btn-primary">自动生成mps</button>
            <button class="layui-btn" lay-submit lay-filter="search">
                查询
            </button>
            <button type="button" class="layui-btn demo-class-accept" lay-options="{accept: 'file'}">
                <i class="layui-icon layui-icon-upload"></i>
                上传文件
            </button>
        </div>

    </form>
    <table class="layui-hide" id="ID-table-demo-search"></table>

    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            var table = layui.table;
            var upload = layui.upload;
            var $ = layui.$;


            //导入
            upload.render({
                elem: '.demo-class-accept', // 绑定多个元素
                url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanImport", // 此处配置你自己的上传接口即可
                accept: 'file', // 普通文件
                done: function (res) {
                    console.log(111,res);
                    if (res.code == 1) {
                        layer.msg('上传成功');
                        setTimeout(function () {
                            location.reload();//刷新页面
                        }, 1000)
                    }
                }
            });


            var formData = {
                produceplanNumber: "",
                produceplanName: "",
                produceplanStatus: -1,
            };
            Seach();

            // 提交事件
            form.on('submit(search)', function (data) {
                var field = data.field; // 获取表单字段值
                // 显示填写结果，仅作演示用
                formData.produceplanNumber = $("#produceplanNumber").val();
                formData.produceplanName = $("#produceplanName").val();
                formData.produceplanStatus = $("#produceplanStatus").val()
                Seach();
                return false; // 阻止默认 form 跳转
            });

            // 搜索提交
            function Seach() {
                console.log(formData);
                var ProcessUrl = '@ViewBag.RBACWrite' + "/api/produceplan/produceplanList?produceplanNumber=" + formData.produceplanNumber + '&produceplanName=' + formData.produceplanName + '&produceplanStatus=' + formData.produceplanStatus;
                $.ajax({
                    url: ProcessUrl,
                    type: 'get',
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        table.render({
                            elem: '#ID-table-demo-search',
                            cols: [
                                [
                                    { field: 'produceplanId', title: '序号', width: 80 },
                                    { field: 'produceplanNumber', title: '计划编码', width: 120 },
                                    { field: 'produceplanName', title: '计划名称', width: 120 },
                                    { field: 'makeName', title: '制单人', width: 100 },
                                    { field: 'makeDepartmentName', title: '制单部门', width: 100 },
                                    { field: 'createTime', title: '创建时间', width: 100 },
                                    { field: 'produceplanStatusName', title: '状态', width: 100 },
                                    { field: 'produceplanAuditName', title: '审批状态', width: 100 },
                                    {
                                        fixed: 'right',
                                        title: '操作',
                                        width: 134,
                                        minWidth: 125,
                                        templet: '#toolDemo',
                                    },
                                ],
                            ],
                            toolbar: '#demo-toolbar-setRowChecked',
                            data: res.data,
                            page: true,
                            limits: [2, 3, 4],
                            height: 310
                        });
                        return;

                    }
                });
            };
            form.on('submit(Del)', function () {
                // 行单击事件( 双击事件为: rowDouble )
                table.on('row(ID-table-demo-search)', function (obj) {
                    var id = obj.data.produceplanId; // 获取当前行数据
                    console.log(id);
                    var data = {
                        produceplanId: id
                    };
                    $.post({
                        url: '@ViewBag.RBACWrite' + "/api/produceplan/produceplanDelete",
                        data: JSON.stringify(data),
                        dataType: "json",
                        contentType: "application/json",
                        success: res => {
                            if (res.code == 1) {
                                layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                                    setTimeout(function () {
                                        location.reload();//刷新页面
                                    }, 500)
                                });
                            }
                            else {
                                layer.alert("删除失败");
                                return;
                            }
                        }
                    })
                });

            });
            form.on('submit(Upd)', function () {
                // 行单击事件( 双击事件为: rowDouble )
                table.on('row(ID-table-demo-search)', function (obj) {
                    var id = obj.data.produceplanId; // 获取当前行数据
                    console.log(id);
                    localStorage.setItem("ProduceplanId", id);
                    location.href = '/produceplan/produceplanUpdate';
                });
            });
        });

    </script>
    <script type="text/html" id="toolDemo">
        <div class="layui-clear-space" >
            <a lay-submit style = "color:cornflowerblue;cursor:pointer"   lay-filter="Upd" > 编辑 </a>&emsp;&emsp;
                <a lay-submit style = "color:red;cursor:pointer" lay-filter="Del" > 删除 </a>
        </div>
    </script>
</body>
</html>
